package com.org.cys.pojo.information.data;

import java.util.ArrayList;
import java.util.List;

import com.org.cys.util.MapUtil;
import com.org.cys.util.PageData;
import com.org.cys.util.StringUtil;

/**
 * 新闻枚举字段转换类
 * @author caiyushen
 * */
public class NewsEnum{
	
	/**
	 * 批量转换成中文枚举类型
	 * @param dataList news数据
	 * */
	public static List<PageData> convert(List<PageData> dataList){
		int dataListSize = dataList.size();
		for(int i=0;i<dataListSize;i++){
			PageData pd = dataList.get(i);
			NewsStatus.convertName(pd);
		}
		return dataList;
	}
	
	/**
	 * 批量转换成中文枚举类型-带样式的<span></span>
	 * @param dataList news数据
	 * */
	public static List<PageData> convertColor(List<PageData> dataList){
		int dataListSize = dataList.size();
		for(int i=0;i<dataListSize;i++){
			PageData pd = dataList.get(i);
			NewsStatus.convertNameColor(pd);
		}
		return dataList;
	}
	
	/**
	 * 转换成中文枚举类型
	 * @param pd news数据
	 * */
	public static PageData convert(PageData pd){
		NewsStatus.convertName(pd);
		return pd;
	}
	
	
	
	/**
	 * 权限类型枚举类
	 * */
	public enum NewsStatus{
		//声明枚举变量
		publish("已发布",1),
		unpublish("未发布",2);
		
		//枚举中文值
		private String name;
		//枚举值
		private Integer index;
		
		private NewsStatus(String name,int index ){
			this.name = name;
			this.index = index;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public Integer getIndex() {
			return index;
		}

		public void setIndex(Integer index) {
			this.index = index;
		}
		
		/**
		 * 枚举值转换成中文
		 * */
		public static PageData convertName(PageData pd){
			Integer newsStatus = MapUtil.getInteger(pd, "newsStatus");
			if(StringUtil.checkObj(newsStatus)){
				switch(newsStatus){
					case 1:
						pd.put("newsStatusStr", NewsStatus.publish.getName());
						break;
					case 2:
						pd.put("newsStatusStr", NewsStatus.unpublish.getName());
						break;
				}
			}
			return pd;
		}
		
		public static PageData convertNameColor(PageData pd){
			Integer newsStatus = MapUtil.getInteger(pd, "newsStatus");
			if(StringUtil.checkObj(newsStatus)){
				switch(newsStatus){
					case 1:
						pd.put("newsStatusStr", "<span style='color:green;'>"+NewsStatus.publish.getName()+"</span>");
						break;
					case 2:
						pd.put("newsStatusStr", "<span style='color:red;'>"+NewsStatus.unpublish.getName()+"</span>");
						break;
				}
			}
			return pd;
		}
		
	}
	
	
	//测试方法
	public static void main(String args[]){
		List<PageData> dataList = new ArrayList<>();
		PageData pd = new PageData();
		pd.put("newsStatus", 1);
		dataList.add(pd);
		convert(pd);
		convert(dataList);
		System.out.println(pd.toString());
	}
	
	
}